
package com.tsh.core.context.config;

import com.tsh.core.context.ServletHttpHeadersGetter;
import com.tsh.core.context.TshContext;
import com.tsh.core.context.TshHttpHeadersGetter;
import com.tsh.core.context.TshServletContext;
import com.tsh.core.context.props.TshContextProperties;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

/**
 * tsh 服务上下文配置
 *
 * @author Tsh
 */
@AutoConfiguration
@Order(Ordered.HIGHEST_PRECEDENCE)
@EnableConfigurationProperties(TshContextProperties.class)
public class TshContextAutoConfiguration {

	@Bean
	@ConditionalOnMissingBean
	public TshHttpHeadersGetter tshHttpHeadersGetter(TshContextProperties contextProperties) {
		return new ServletHttpHeadersGetter(contextProperties);
	}

	@Bean
	@ConditionalOnMissingBean
	public TshContext tshContext(TshContextProperties contextProperties, TshHttpHeadersGetter httpHeadersGetter) {
		return new TshServletContext(contextProperties, httpHeadersGetter);
	}

}
